/**
 * @Copyright (c) 2006,东登信息网络有限公司
 * @All rights reserved.
 *
 * 用于Ajax读取数据显示 || 直接显示数据 || 显示图片
 * 如果使用ajax,需要加载DAjax类,只用户读取某个页面内容
 * 如果使用效果,需要加载Effect
 * 如果使用拖动,需要加载DragDrop
 *
 * @file_name   LightBox.js
 * @version     1.0
 * @author      黄新泽
 * @date        2007-10-08 16:09:40
 */

/**
 * Class and Function List:
 * Function list:
 * - initialize: function()
 * - addLightboxMarkup: function(s)
 * - activate: function()
 * - prepareIE: function(height, overflow)
 * - hideSelects: function(visibility)
 * - getScroll: function()
 * - setScroll: function(x, y)
 * - displayLightbox: function(display)
 * - loadInfo: function(url, arg)
 * - responseData : function(response, ajaxObj)
 * - processInfo: function(response, type)
 * - function resizeLightBox()
 * - actions: function()
 * - insert: function(e)
 * - deactivate: function()
 * - remove: function()
 * - tag: function(ctrl)
 * - doTag : function(event)
 * - function initialize()
 * Classes list:
 * - .LightBox
 */



var LightBox = Class.create({
	yPos : 0,
	xPos : 0,
	box : {id:0, zIndex:500, tId:0},
	ajaxObj : [],
	ajaxId : 0,
	imageId : 0,
	eb :{eid:0},
	cTOption :{click:[], dblClick:[]},

	cOption :{click:[], dblClick:[]},
	maxOption :{click:[], dblClick:[]},
	minOption :{click:[], dblClick:[]},
	titleOption :{click:[], dblClick:[]},

	restoreData : [{}],
	restoreTData : [{}],
	maxStyle : {top:"0px", left:"0px", width:"100%", height:"100%", borderLeftWidth:"0px", borderRightWidth:"0px", borderTopWidth:"0px", borderBottomWidth:"0px"},
	minStyle : {top:"0px", left:"10px", width:"150px", height:"auto"},

	tooltipSingleton : [],
	empty : function(){return false;},

	/**
	 * 构造函数
	 *
	 * @access	public
	 */
	initialize: function()
	{
		++ this.eb.eid;

		this.init();

		document.observe('keydown', function (evt)
		{
			if (27 == evt.keyCode)
			{
				if ('input'==evt.element().tagName.toLowerCase() || 'textarea'==evt.element().tagName.toLowerCase())
				{
				}
				else
				{
					if (box.box.id)
					{
						evt.stop();
						box.remove();
					}
					else
					{
						evt.stop();
					}
				}
			}
			else
			{
			}

			return true;
		});

	},

	init: function()
	{
		var lbox = $$('.O');

		for(i = 0; i < lbox.length; i++)
		{
			box.tag(lbox[i]);
			lbox[i] = null;
		}
		
		//处理tooltip
		lbox = $$('.T');

		for(i = 0; i < lbox.length; i++)
		{
			this.tagT(lbox[i]);
			lbox[i] = null;
		}

		lbox = null;
	},

	/**
	 * 生成遮罩,此处没有定义高度,宽度.放在最后显示处定义.
	 *
	 *	<div id="overlay1" class="overlay" style="z-index: 501;"/>
	 *	<div id="lightbox1" class="lightbox loading" style="z-index: 502;">
	 *		<div class="title" id="title1"/>
	 *		<a href="javascript:;" title= "点击最小" id="min" class="lb_min" ><img src="' + IMA_PATH + '/js/min.gif" border="0"  alt="点击最小"></a>
	 *		<a href="javascript:;" title= "点击放大" id="max" class="lb_max" ><img src="' + IMA_PATH + '/js/max.gif" border="0"  alt="点击放大"></a>
	 *		<a href="javascript:;" title= "点击关闭" id="c" class="lb_close" ><img src="' + IMA_PATH + '/js/close.gif" border="0"  alt="点击关闭"></a>
	 *		<div style="z-index: 502;" class="lbContainer" id="lbContainer1">
	 *			<div class="contents" id="contents1"/>
	 *		</div>
	 *		<div class="lbLoadMessage" id="lbLoadMessage1" style="display: none;"><img src="' + IMA_PATH + '/js/loading2.gif"/></div>
	 *	</div>
	 * @param Int	s	overlay styoe
	 * @access	public
	 */
	addLightboxMarkup: function(s)
	{
		this.box.id ++ ;
		this.box.zIndex ++ ;
		var bod			= document.getElementsByTagName('body')[0];

		//生成遮罩
		var overlay		= document.createElement('div');
		overlay.id		= 'overlay' + this.box.id;
		overlay.className 	= 'overlay';
		overlay.style.zIndex = this.box.zIndex ;
		overlay.style.display = 'none' ;

		var pg = getPageSize();
		overlay.style.height = pg[1] + 'px'; ;

		//生成lightbox
		this.box.zIndex ++ ;
		var lb			= document.createElement('div');
		lb.id			= 'lightbox' + this.box.id;
		lb.className 	= 'lightbox loading';
		lb.style.zIndex = this.box.zIndex;

		// lightbox中放入表现形式,调用样式类生成
		var style_contents = '<div id="title' + this.box.id + '"  class="title" style="display:none;"><div><span id="tc' + this.box.id + '" class="title_text">&nbsp;</span>\
							<a href="javascript:;" title= "点击最小" id="min' + this.box.id + '" class="lb_min" ><img src="' + IMA_PATH + '/js/min.gif"  height="14" width="15" border="0"  alt="点击最小"></a>\
							<a href="javascript:;" title= "点击放大" id="max' + this.box.id + '" class="lb_max" ><img src="' + IMA_PATH + '/js/max.gif" height="14" width="15"  border="0"  alt="点击放大"></a>\
							<a href="javascript:;" title= "点击关闭" id="c' + this.box.id + '" class="lb_close" ><img src="' + IMA_PATH + '/js/close.gif" height="20" width="20"  border="0"  alt="点击关闭"></a></div></div>\
							<div id="lbContainer' + this.box.id + '" class="lbContainer" style="display:none;z-index:' + this.box.zIndex + '">\
								<div  id="contents' + this.box.id + '" class="contents"><table  style="width:100%;height:100%;text-align: center;"  id="lbTbale' + this.box.id + '" ><tr><td><table  style="width:1%;height:1%;text-align: center;" align="center" ><tr><td id="contents_table' + this.box.id + '" style="display:none;"><div style="display:none;"></div></td></tr></table></td></tr></table></div>\
							</div>\
							<div id="lbLoadMessage' + this.box.id + '"  class="lbLoadMessage">' + '<img  height="89" width="90" src="' + IMA_PATH + '/js/loading2.gif">' + '</div>\
							<div id="bottom' + this.box.id + '"  class="bottom"></div>';
		lb.innerHTML	= style_contents;
		bod.appendChild(overlay);
		bod.appendChild(lb);

//		this.cOption.click[this.box.id] = this.remove.bindAsEventListener(this);
//		this.maxOption.click[this.box.id] = this.max.bindAsEventListener(this);
//		this.minOption.click[this.box.id] = this.min.bindAsEventListener(this);
//		this.titleOption.dblClick[this.box.id] = this.max.bindAsEventListener(this);
//
//		Event.observe($('c' + this.box.id), 'click', this.cOption.click[this.box.id], false);
//		Event.observe($('max' + this.box.id), 'click', this.maxOption.click[this.box.id], false);
//		Event.observe($('min' + this.box.id), 'click', this.minOption.click[this.box.id], false);
//		Event.observe($('title' + this.box.id), 'dblclick', this.titleOption.dblClick[this.box.id], false);
//
//		$('c' + this.box.id).onclick = $('max' + this.box.id).onclick = $('min' + this.box.id).onclick = $('title' + this.box.id).onclick = this.empty;

		bod = null;
		pg = null;
		style_contents = null;
		overlay = null;
		lb = null;

		$('lbLoadMessage' + this.box.id).hide(); //屏蔽默认显示加载框,什么都不显示,需要加载的,单独打开
	},



	addWindow: function(event, option)
	{
		this.box.tId ++ ;
		this.box.zIndex += 2  ;

		var bod			= document.getElementsByTagName('body')[0];

		// old
		var style_contents = '';

		 style_contents = '<table id="tooltip' + this.box.tId + '" style="width:1%;height:1%;text-align: center;position: absolute;top:' + option.y + 'px;left:' + option.x + 'px;z-index:' + this.box.zIndex + ';" align="center" ><tr><td id="tooltip_cts' + this.box.tId + '"></td></tr></table>\
							';

		//tooltip.innerHTML = style_contents;
		bod.insert(style_contents);

		bod = null;
		style_contents = null;



		this.prepareIE('100%', 'hidden');
	},


	addHelpWindow: function(s)
	{
		var bod			= document.getElementsByTagName('body')[0];

		//生成lightbox

		var lb			= document.createElement('div');
		lb.id			= 'lightbox_help';
		lb.className 	= 'lightbox loading no_scroll';
		lb.style.zIndex = 499;

		// lightbox中放入表现形式,调用样式类生成
		var style_contents = '<!--div id="title_help"  class="title"><div><span id="tc_help" class="title_text">&nbsp;</span>\
							<a href="javascript:;" title= "点击最小" id="min_help" class="lb_min" ><img src="' + IMA_PATH + '/js/min.gif" border="0"  alt="点击最小"></a>\
							<a href="javascript:;" title= "点击放大" id="max_help" class="lb_max" ><img src="' + IMA_PATH + '/js/max.gif" border="0"  alt="点击放大"></a>\
							</div></div-->\
							<a href="javascript:;" title= "点击关闭" id="c_help" class="lb_close"  onclick="Element.hide(\'lightbox_help\')"><img src="' + IMA_PATH + '/js/close.gif" border="0"  alt="点击关闭"></a>\
							<div id="lbContainer_help" class="lbContainer no_scroll" style="z-index:' + this.box.zIndex + '">\
								<div  id="contents_help" class="contents no_scroll"><iframe class="help_iframe" id="help_url"  width="100%" height="524" frameborder="0" scrolling="no" src="javascript:false;" style="background:transparent;" ></iframe></div>\
							</div>\
							<div id="lbLoadMessage_help"  class="lbLoadMessage">' + '<img src="' + IMA_PATH + '/js/loading2.gif">' + '</div>\
							<div id="bottom_help"  class="bottom"></div>';
		lb.innerHTML	= style_contents;

		bod.appendChild(lb);

//		this.cOption.click[this.box.id] = this.remove.bindAsEventListener(this);
//		this.maxOption.click[this.box.id] = this.max.bindAsEventListener(this);
//		this.minOption.click[this.box.id] = this.min.bindAsEventListener(this);
//		this.titleOption.dblClick[this.box.id] = this.max.bindAsEventListener(this);
//
//		Event.observe($('c' + this.box.id), 'click', this.cOption.click[this.box.id], false);
//		Event.observe($('max' + this.box.id), 'click', this.maxOption.click[this.box.id], false);
//		Event.observe($('min' + this.box.id), 'click', this.minOption.click[this.box.id], false);
//		Event.observe($('title' + this.box.id), 'dblclick', this.titleOption.dblClick[this.box.id], false);
//
//		$('c' + this.box.id).onclick = $('max' + this.box.id).onclick = $('min' + this.box.id).onclick = $('title' + this.box.id).onclick = this.empty;

		bod = null;
		style_contents = null;
		lb = null;

		$('lbLoadMessage_help').hide(); //屏蔽默认显示加载框,什么都不显示,需要加载的,单独打开
		console.info('生成帮助窗口');

		'undefined' == typeof(Draggable) ? null : new Draggable('lightbox_help');
	},


	addMsgWindow: function(s)
	{
		this.box.zIndex ++ ;

		var bod			= document.getElementsByTagName('body')[0];

		//生成遮罩
		var overlay		= document.createElement('div');
		overlay.id		= 'overlay_msg';
		overlay.className 	= 'overlay';
		overlay.style.zIndex =  this.box.zIndex ;

		var pg = getPageSize();
		overlay.style.height = pg[1] + 'px'; ;

		//生成lightbox
		this.box.zIndex ++ ;
		var lb			= document.createElement('div');
		lb.id			= 'lightbox_msg';
		lb.className 	= 'lightbox loading';
		lb.style.zIndex =  this.box.zIndex;

		// lightbox中放入表现形式,调用样式类生成
		var style_contents = '<div id="lbContainer_msg" class="lbContainer" style="z-index:50001">\
								<a href="javascript:;" title= "点击关闭" id="c' + this.box.id + '" class="lb_close" ><img src="' + IMA_PATH + '/js/close.gif" border="0"  alt="点击关闭">FFFFFFFF</a>\
								<div  id="contents_msg" class="contents"><table  style="width:100%;height:100%;text-align: center;"  id="lbTbale_msg" ><tr><td><table  style="width:1%;height:1%;text-align: center;" align="center" ><tr><td id="contents_table_msg"></td></tr></table></td></tr></table></div>\
							</div>\
							<div id="lbLoadMessage_msg"  class="lbLoadMessage"><a href="javascript:;" title= "点击关闭" id="c_msg" class="lb_close" ></a><img src="' + IMA_PATH + '/js/loading2.gif" /></div>\
							<div id="bottom_msg"  class="bottom"></div>';
		lb.innerHTML	= style_contents;
		bod.appendChild(overlay);
		bod.appendChild(lb);

		bod = null;
		pg = null;
		style_contents = null;
		overlay = null;
		lb = null;

		$('lbLoadMessage_msg').show();

		var lb = $('lightbox_msg');
		var lct =$('lbContainer_msg');
		var ct = $('contents_msg');

		var w=100;
		var h=100;

		var arrayPageScroll = getPageSize();
		var lightboxTop = ((document.viewport.getHeight() - 35 - h) / 2);
		var lightboxLeft = ((document.viewport.getWidth() - 20 - w) / 2);

		if (Prototype.Browser.IE && !Prototype.Browser.IE7)
		{
			Position.prepare();
			lightboxTop += Position.deltaY;
		}

		lct.style.width = w + "px";
		lct.style.height = h + "px";

		lb.style.width = w + "px";
		lb.style.height = h + "px";
		lb.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
		lb.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
		lb.style.margin = '0px';

		this.prepareIE('100%', 'hidden');

		//ajax请求并没有取消
		$('c_msg').observe('click', this.removeMsg.bind(this), false);

		lb = null;
		lct = null;
		ct = null;
	},


	/**
	 * 返回提示消息框
	 *
	 * @access	public
	 */
	getMsgBox: function(close)
	{
		//另外一种结构
		/*
		<div style='width: 750px;position:relative;'>
			<a title="关闭" onclick="return box.remove();" class="lb_close"></a>
			<div class="stage_top"><div class="stage_top_right"></div><div class="stage_top_left"></div></div>
			<div class="stage_body">
				<div class="stage_content" >
					反反复反复反复
				</div>
			</div>
			<div class="stage_bottom"><div class="stage_bottom_right"></div><div class="stage_bottom_left"></div></div>
		</div>
		*/
		try 
		{
			if (close == 2)
			{
				msgBox = '<div style="position: relative;">\
							<a title="' + _('close') + '"  class="lb_close" onclick="return box.remove();"></a>\
							#{msg}\
						</div>';
			}
			else
			{
				var msgBox = '\
						<div class="dlg_border">';
				msgBox += '<a title="' + _('close') + '"  class="lb_close" onclick="return box.remove();"></a>';
				msgBox += '<div class="dlg_frame">\
								<div class="dlg_top_border">\
									<div class="dlg_right_border">\
										<div class="dlg_bottom_border">\
											<div class="dlg_left_border">\
												<div class="dlg_left_bottom">\
													<div class="dlg_right_bottom">\
														<div class="dlg_left_top">\
															<div class="dlg_right_top">\
																<div class="dlg_content #{classname}">\
																	#{msg}\
																</div>\
															</div>\
														</div>\
													</div>\
												</div>\
											</div>\
										</div>\
									</div>\
								</div>\
							</div>\
						</div>\
						<div class="dlg_bottom"></div>\
					';

			}

			return msgBox;
		}
		finally
		{
			msgBox = null;
		}
	},


	/**
	 * 返回提示消息框
	 *
	 * @access	public
	 */
	getTipBox: function(close, id, t)
	{
		try 
		{
			var msgBox = '\
						<div class="dlg_tip_border">';

				msgBox += '<div class="dlg_frame">\
							<div class="dlg_content #{classname}">';
			if (close)
			{
				if (Object.isUndefined(t))
				{
				}
				else
				{
					msgBox += '<div class="dlg_title drag_title" id="tip_title' + id + '">' + t + '</div>';				
				}

				msgBox += '<a title="' + _('close') + '" onclick="box.removeTip(' + id + ');" class="lb_close" ></a>';
			}
				msgBox += '			#{msg}\
								</div>\
							</div>\
						</div>\
						<div class="dlg_bottom"></div>\
					';

			return msgBox;

		}
		finally
		{
			msgBox = null;
		}
	},

	/**
	 * 返回提示消息框
	 *
	 * @access	public
	 */
	getTipBox2: function(close, id, t)
	{
		try 
		{
			var msgBox = '\
						<div class="help_tip">';

				msgBox += '<div class="top"></div>\
												<div class="middle #{classname}">';
			if (close)
			{
				if (Object.isUndefined(t))
				{
				}
				else
				{
					msgBox += '<div class="dlg_title drag_title" id="tip_title' + id + '">' + t + '</div>';				
				}

				msgBox += '<a title="' + _('close') + '" onclick="return box.removeTip(' + id + ');" class="lb_close" ></a>';
			}
				msgBox += '							#{msg}\
												</div>\
							<div class="bottom"></div>\
						</div>\
					';

			return msgBox;
		}
		finally
		{
			msgBox = null;
		}
	},

	/**
	 * 默认提示
	 *
	 * @access	public
	 */
	showMsgBox: function(msg_contents, t, close, classname)
	{
		if (Object.isUndefined(close))
		{
			close = true;
		}

		if (!classname)
		{
			classname = '';
		}
		else
		{
			msg_contents = "<table style='width:100%;height:30px;'><tr><td>" + msg_contents + "</td></tr></table>";
		}


		var tpl = new Template(this.getMsgBox(close, classname));
		var msg = {msg:msg_contents, classname:classname};

		var msg_box = tpl.evaluate(msg);

		if (!t)
		{
			t = 'n';
		}

		msg_contents = null;
		msg = null;
		tpl = null;

		try
		{
			return box.processInfo(msg_box, t);
		}
		finally
		{
			msg_box = t = null;
		}
		
	},

	/**
	 * 默认提示
	 *
	 * @access	public
	 */
	msg: function(msg_contents, t, close, classname)
	{
		try
		{
			return this.showMsgBox(msg_contents, t, close, classname);
		}
		finally
		{
			msg_contents = t = close = classname = null;
		}
	},


	/**
	 * 默认提示
	 *
	 * @access	public
	 */
	m: function(msg_contents, t, close)
	{
		try
		{
			return this.showMsgBox(msg_contents, t, close, 'center');
		}
		finally
		{
			msg_contents = t = close = null;
		}
	},

	/**
	 * 默认提示
	 *
	 * @access	public
	 */
	confirm: function(msg, click, t, confirm, cancel)
	{
		try
		{
			return this.c(msg, click, t, confirm, cancel);
		}
		finally
		{
			msg = click = t  = confirm = cancel = null;
		}
		
	},

	/**
	 * 默认提示
	 *
	 * @access	public
	 */
	c: function(msg, click, t, confirm, cancel)
	{
		var s = '\
			<table style="width: 300px;" class="box">\
			<tbody>\
				<tr>\
					<td align="center">\
						<table align="center">\
							<tbody>\
								<tr>\
									<td class="message">\
										#{msg}\
									</td>\
								</tr>\
							</tbody>\
						</table>\
					</td>\
				</tr>\
				<tr>\
					<td class="buttons"><input type="submit" value="#{confirm}" class="button" onclick="#{click};box.remove();" /><input type="button" value="#{cancel}" class="button" onclick="box.remove();" /></td>\
				</tr>\
			</tbody>\
			</table>\
		';

		if (Object.isUndefined(confirm) || !confirm)
		{
			confirm = '确认';
		}


		if (Object.isUndefined(cancel) || !cancel)
		{
			cancel = '取消';
		}

		var tpl = new Template(s);
		var msg = {msg:msg, click:click, confirm:confirm, cancel:cancel};

		var msg_box = tpl.evaluate(msg);
		
		s = msg = t =null;

		try
		{
			return this.m(msg_box, t);
		}
		finally
		{
			msg_box = t = null;
		}
	},
	/**
	 * Turn everything on - 调整IE问题
	 *
	 * @access	public
	 */
	activate: function()
	{
		if (Prototype.Browser.IE)
		{
			//this.getScroll();
			this.prepareIE('100%', 'hidden');
			//this.setScroll(0, 0);
			this.hideSelects('hidden');
		}

		this.displayLightbox("block");
	},

	/**
	 * Ie requires height to 100% and overflow hidden or else you can scroll down past the lightbox
	 *
	 * @param Int		height		Body 高度
	 * @param String	overflow	Body overflow
	 *
	 * @access	public
	 */
	prepareIE: function(height, overflow)
	{
		/*
		var bod = document.getElementsByTagName('body')[0];
		bod.style.height = height;
		//bod.style.overflow = overflow;

		var htm = document.getElementsByTagName('html')[0];
		htm.style.height = height;
		//htm.style.overflow = overflow;

		bod = null;
		htm = null;
		*/
	},

	/**
	 * 解决Ie  select 控件z-index总是最高bug
	 *
	 * @param String	visibility	style.display
	 *
	 * @access	public
	 */
	hideSelects: function(visibility)
	{
		var selects = null;

		//显示隐藏问题
		if ('hidden' == visibility)
		{
			if (1 == this.box.id)
			{
				selects = document.getElementsByTagName('select');
			}
			else
			{
				var i = this.box.id - 1 ;
				selects = $('lightbox' + i).getElementsByTagName('select');
			}
		}
		else
		{
			if (1 == this.box.id)
			{
				selects = document.getElementsByTagName('select');
			}
			else
			{
				var i = this.box.id - 1 ;
				selects = $('lightbox' + i).getElementsByTagName('select');
			}
		}


		for(i = 0; i < selects.length; i++)
		{
			selects[i].style.visibility = visibility;
		}

		selects = null;
		i = null;
	},

	/**
	 * 处理滚动条
	 *
	 * @access	public
	 */
	getScroll: function()
	{
		Position.prepare();
		this.yPos = Position.deltaY;
	},

	/**
	 * 重新设置滚动位置
	 *
	 * @access	public
	 */
	setScroll: function(x, y)
	{
		window.scrollTo(x, y);
	},

	/**
	 * 显示还是隐藏控件
	 *
	 * @param String	display	style.display
	 *
	 * @access	public
	 */
	displayLightbox: function(display)
	{

		$('lightbox' + this.box.id).style.display = display;

		if ('block_w' == display)
		{
			Effect.Appear($('overlay' + this.box.id), {to: 0.5, from: 0.0});
		}
		else
		{
			$('overlay' + this.box.id).style.display = display;
		}
	},


	load: function(url, arg)
	{
		if (!url)
		{
			return false;
		}

		var option = {option:{onSuccess:this.responseData.bind(this), lbType:'n' }, logic:{type:"e"}};
		Object.extend(option, arg);
		this.ajaxId ++ ;

		//DHistory.add('box.loadInfo_' + url , arguments);

		option.option.onSuccess = this.responseData.bind(this);

		//可以判断类是否初始化,暂时没有判断, ( 消息机制错乱,问题严重,可能用法取消,或者重新编码解决) -> 已经解决
		this.ajaxObj[this.ajaxId] = new DAjax(url, option);
		this.ajaxObj[this.ajaxId].sendRequest();

		option = null;
		url = null;
		arg = null;
	},

	// Begin Ajax request based off of the href of the clicked linked
	// Display Ajax response or text
	/**
		arg = {
			text:'msg',
			type:'n' or 'o'
			method: 'post',
			parameters: ""
		}
	*/
	/**
	 * DAjax取得数据
	 *
	 * @param String	url		请求地址
	 * @param Object	arg		请求附带的参数
	 *
	 * @access	public
	 */
	loadInfo: function(url, arg)
	{
		this.load(url, arg);
	},

	/**
	 * 处理DAjax返回数据
	 *
	 * @param Object	response	response
	 * @param Object	ajaxObj		DAjax句柄
	 *
	 * @access	public
	 */
	responseData : function(responseText, ajaxObj)
	{
		var t_id = ajaxObj.option.tId;

		if ('t' == ajaxObj.lbType)
		{
			var tpl = new Template(this.getTipBox(true, t_id));
		}
		else
		{
			var tpl = new Template(this.getMsgBox(true, true));
		}


		var msg = {msg:responseText};

		var msg_box = tpl.evaluate(msg);

		this.processInfo(msg_box, ajaxObj.lbType, null, t_id);

		ajaxObj.msg.removeMessage();
		ajaxObj.collectCarbage();

		this.ajaxObj[this.ajaxId] = null;
		this.ajaxId --;

		responseText = null;		
		t_id = null;
		ajaxObj = null;
	},

	/**
	 * 显示数据
	 *
	 * @param Object	response	response
	 * @param String	type		显示类型
	 * @param String	title		显示标题
	 *
	 * type == t , tooltip                
	 * type == n , 生成新box内容信息  == new 
	 * type == o , 覆盖当前box内容信息 == old 
	 * type == i , image, type相当于 new    
	 * 
	 * @access	public
	 */
	processInfo: function(response, type, title, t_id)
	{
		if ('t' == type)
		{
			$('tooltip_cts' + t_id).edit(response);

			var tip_offset_left = 0;
			var tip_offset_top = 0;

			//未和id绑定,会导致错乱
			var tip_offset = $('tooltip' + t_id).cumulativeOffset();
			var tip_size = $('tooltip' + t_id).getDimensions();
				console.info('tip_offset', tip_offset);
				console.info('tip_size', tip_size);

			if (tip_offset[0] + tip_size.width > document.viewport.getWidth())
			{
				tip_offset_left = tip_offset[0];
			}
			else
			{
				tip_offset_left = tip_offset[0];
			}

			if (tip_offset[1] + tip_size.height > document.viewport.getHeight())
			{
				tip_offset_top = tip_offset[1] - tip_size.height;
				console.info(2);
				console.info(tip_offset_top);
			}
			else
			{
				tip_offset_top = tip_offset[1];

				console.info(1);
				console.info(tip_offset_top);
			}

			$('tooltip' + t_id).setStyle({'left': tip_offset_left + 'px', 'top': tip_offset_top + 'px'}); 



			$('tooltip' + t_id).show();
			//放入了prototype js 中 update  方法中
			//this.actions($('tooltip_cts' + this.box.tId));

			if('undefined' != typeof(Draggable) && $('tip_title' + t_id))
			{
				var d = new Draggable($('tooltip' + this.box.tId), {handle:'tip_title' + this.box.tId});
				d = null;
			}

			response = null;
			return false;
		}

		//窗口默认大小
		var w = document.viewport.getWidth();
		var h = document.viewport.getHeight();

		//因为有覆盖问题,所以.. ..
		if ('o' == type)
		{
			if (!this.box.id)
			{
				type = 'n';
				this.addLightboxMarkup();
				this.activate();
			}
		}
		else
		{
			this.addLightboxMarkup();
			this.activate();
		}

		$('tc' + this.box.id).edit(title);

		var lb = $('lightbox' + this.box.id);
		var lct =$('lbContainer' + this.box.id);
		var ct = $('contents' + this.box.id);
		var ctt = $('contents_table' + this.box.id);
		var ctable = $('lbTbale' + this.box.id);

		if ('o' == type)
		{
			ctt.edit(response);
			//new Insertion.Top(ctt, '<div  class="sg_jz_b_bg_new"><img src="' + IMA_PATH + '/main/jz_b_6.gif" rel="remove" class="lbAction" style="float:right;"  /></div>');

			resizeLightBox();
		}
		else
		{
			//如果是图片
			if ('i' == type)
			{
				w = h = 100;

				resizeLightBox();
				//打开加载显示框
				$('lbLoadMessage' + this.box.id).show();

				//prototype_1.6.0_rc0.js  降低到prototype_1.5.1.js bug 解决
				//var objImage = document.createElement("img");
				//objImage.setAttribute('id','lightboxImage' + this.box.id);
				var objImage = '<img id="lightboxImage' + this.box.id +'" border="0" />';

				lct.style.overflow = 'visible' ;
				ctt.edit(objImage);

				objImage = $('lightboxImage' + this.box.id);

				//点击关闭
				objImage.observe('click', this.remove.bind(this), false);

				// preload image
				imgPreload = new Image();

				imgPreload.onload=function()
				{
					objImage.src = response;
					// center lightbox and make sure that the top and left values are not negative
					// and the image placed outside the viewport
					w = imgPreload.width;
					h = imgPreload.height;

					ct.style.width = w + "px";
					ct.style.height = h + "px";

					// A small pause between the image loading and displaying is required with IE,
					// this prevents the previous image displaying for a short burst causing flicker.
					if (Prototype.Browser.IE)
					{
						//pause(250);
						//pause(25);
					}

					imgPreload.onload=function(){};	//	clear onLoad, as IE will flip out w/animated gifs

					resizeLightBox();
					lb.removeClassName("loading");
					response = null;
					return false;
				};

				imgPreload.src = response;

				objImage = null;
			}
			else
			{
				ctt.edit(response);
				//new Insertion.Top(ctt, '<div  class="sg_jz_b_bg_new"><img src="' + IMA_PATH + '/main/jz_b_6.gif" rel="remove" class="lbAction" style="float:right;"  /></div>');

				resizeLightBox();
				lb.removeClassName("loading");
			}

			lb.addClassName("done");
		}

		//效果
		if('undefined' != typeof(Effect_w))
		{
			//如果使用效果， 则之前需要将显示的div 的 style.display=none
			//Effect.Grow(lct,{});

			if (Prototype.Browser.IE)
			{
				lct.show();
				Effect.Grow(ctt,{});
			}
			else
			{
				ctt.show();
				Effect.Grow(lct,{});
			}

			//Effect.Grow(lct,{duration:2.0});
		}
		else
		{
			ctt.show();
			lct.show();
		}

		function resizeLightBox()
		{
			var arrayPageScroll = getPageSize();
			var lightboxTop = ((document.viewport.getHeight() - 35 - h) / 2);
			var lightboxLeft = ((document.viewport.getWidth() - 20 - w) / 2);

			if (Prototype.Browser.IE && !Prototype.Browser.IE7)
			{
				Position.prepare();
				lightboxTop += Position.deltaY;
			}

			ctable.style.width = w + "px";
			ctable.style.height = h + "px";

			ct.style.width = w + "px";
			ct.style.height = h + "px";

			lct.style.width = w + "px";
			lct.style.height = h + "px";

			lb.style.width = w + "px";
			lb.style.height = h + "px";
			lb.style.top = (lightboxTop < 0) ? "0px" : lightboxTop + "px";
			lb.style.left = (lightboxLeft < 0) ? "0px" : lightboxLeft + "px";
			lb.style.margin = '0px';

			arrayPageScroll = null;
			lightboxTop = null;
			lightboxLeft = null;
		}

		//resize('lbContainer' + this.box.id, 'contents' + this.box.id);
		//如果ajax取得数据,取回的数据是否要处理?

		//放入了prototype js 中 update  方法中
		//this.actions(lb);
		//console.info((new	Date()).getTime());
		if('undefined' != typeof(Effect))
		{
			//Effect.SlideDown('title' + this.box.id,{duration:1.0});
		}

		$('title' + this.box.id).hide();
		//setTimeout("box.drag()", 500);

		response = null;
		type = null;
		lb = null;
		lct = null;
		ct = null;
		ctt = null;
		ctable = null;

		return this.box.id;
	},

	/**
	 * 
	 *
	 * @access	public
	 */
	drag: function()
	{
		try
		{
			//拖动
			if('undefined' != typeof(Draggable))
			{

				var action = $$('#contents' + this.box.id + ' .dlg_title');

				for(i=0; i<action.length; i++)
				{
					var d = new Draggable($('contents' + this.box.id), {handle:action[i]});
					d = null;
				}

				action = null;

			}
		}
		catch(e)
		{}
	},

	/**
	 * 添加事件 Search through new links within the lightbox, and attach click event
	 * 
	 * @access	public
	 */
	actions: function(id)
	{
		var lbActions = $(id).getElementsByClassName('lbAction');

		for(i = 0; i < lbActions.length; i++)
		{
			//Event.observe(lbActions[i], 'click', this[lbActions[i].rel].bindAsEventListener(this), false);
			lbActions[i].observe('click', this[lbActions[i].readAttribute('rel')].bind(this), false);
			lbActions[i].onclick = this.empty;
			lbActions[i] = null;
		}

		lbActions = null;

		var lbox = $(id).getElementsByClassName('O');

		for(i = 0; i < lbox.length; i++)
		{
			box.tag(lbox[i]);
			lbox[i] = null;
		}

		lbox = null;

		//处理tooltip
		lbox = $(id).getElementsByClassName('T');

		for(i = 0; i < lbox.length; i++)
		{
			box.tagT(lbox[i]);
			lbox[i] = null;
		}

		//lbox = $(id).getElementsByClassName('TS');

		//for(i = 0; i < lbox.length; i++)
		//{
			//box.tagTS(lbox[i]);
		//}

		lbox = id = null;

	},

	/**
	 * 用于解决内存泄漏问题,暂时不处理.
	 *
	 * @access	public
	 */
	deActions: function()
	{
		this.restoreData[this.box.id] = false;
	},

	/**
	 * 用于解决内存泄漏问题,暂时不处理.
	 *
	 * @access	public
	 */
	deEvent: function(id)
	{
		/*
		var lbActions = $(id).getElementsByClassName('lbAction');

		for(i = 0; i < lbActions.length; i++)
		{
			lbActions[i].stopObserving('click');
		}

		lbActions = null;

		var lbox = $(id).getElementsByClassName('O');

		for(i = 0; i < lbox.length; i++)
		{
			lbox[i].stopObserving('click');
		}
		lbox = null;

		//处理tooltip
		lbox = $(id).getElementsByClassName('T');

		for(i = 0; i < lbox.length; i++)
		{
			lbox[i].stopObserving('click');
		}

		lbox = $(id).getElementsByClassName('TS');

		for(i = 0; i < lbox.length; i++)
		{
			lbox[i].stopObserving('click');
			lbox[i].stopObserving('mouseover');
			lbox[i].stopObserving('mouseout');
			lbox[i].stopObserving('mousemove');
			lbox[i].stopObserving('blur');
		}

		lbox = null;
		*/
	},

	/**
	 * 处理自定义函数.
	 *
	 * @access	public
	 */
	insert: function(e)
	{
		var link = Event.element(e).parentNode;
		var type = 'n';

		if (isSet(link.type))
		{
			type = link.type;
		}

		this.loadInfo(link.readAttribute('href'), {option:{formName: elt.readAttribute('form'), lbType:type}});
	},

	/**
	 * 处理自定义函数.
	 *
	 * @access	public
	 */
	deactivate: function(e)
	{
		this.remove(e);
	},

	/**
	 * @access	public
	 */
	remove: function(e)
	{

		try 
		{
			if (intVal(this.box.id))
			{
				//this.deEvent($('overlay' + this.box.id));
				//this.deEvent($('lightbox' + this.box.id));

				this.deActions();
				$('overlay' + this.box.id).del();
				$('lightbox' + this.box.id).del();

				if (Prototype.Browser.IE)
				{
					if (1 == this.box.id)
					{
						this.prepareIE("auto", "auto");
					}

					this.hideSelects("visible");
					//this.setScroll(0, this.yPos);
				}

				this.box.id --;
				this.box.zIndex = this.box.zIndex -2  ;
				//this.displayLightbox("none");
			}
		}
		catch(e)
		{}

		return false;
	},

	del: function(id)
	{

		try 
		{
			if (intVal(id))
			{
				this.deEvent($('overlay' + id));
				this.deEvent($('lightbox' + id));

				this.deActions();
				$('overlay' + id).del();
				$('lightbox' + id).del();

				if (Prototype.Browser.IE)
				{
					if (1 == id)
					{
						this.prepareIE("auto", "auto");
					}

					this.hideSelects("visible");
					//this.setScroll(0, this.yPos);
				}

				this.box.id --;
				this.box.zIndex = this.box.zIndex -2  ;
				//this.displayLightbox("none");
			}
		}
		catch(e)
		{}

		return false;
	},

	/**
	 * @access	public
	 */
	removeTip: function(tId)
	{

		try 
		{
			if (tId)
			{
				if ($('tooltip' + tId))
				{
					$('tooltip' + tId).remove();
					this.box.zIndex  = this.box.zIndex - 2;
				}
			}
			else
			{
				if ($('tooltip' + this.box.tId))
				{
					$('tooltip' + this.box.tId).remove();
					this.box.zIndex  = this.box.zIndex - 2;
				}
			}

		}
		catch(e)
		{}

		return false;
	},
	/**
	 * @access	public
	 */
	removeMsg: function(e)
	{

		try 
		{
				$('overlay_msg').del();
				$('lightbox_msg').del();

				if (Prototype.Browser.IE)
				{
					if (1 == this.box.id)
					{
						this.prepareIE("auto", "auto");
					}

					this.hideSelects("visible");
					//this.setScroll(0, this.yPos);
				}

				this.box.zIndex = this.box.zIndex -2  ;
		}
		catch(e)
		{}

		return false;
	},

	/**
	 * @access	public
	 */
	removeById: function(id)
	{
		if (intVal(this.box.id) == id)
		{
			this.del(id);
		}

		return false;
	},

	/**
	 * @access	public
	 */
	setRestoreData: function(lb)
	{
		var currentStyle = {};
		['top', 'left', 'width', 'height', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth', 'borderBottomWidth'].each(function(s) {currentStyle[s] = lb.getStyle(s)});

		if (!this.restoreData[this.box.id])
		{
			this.restoreData[this.box.id] = currentStyle;
		}

		lb = null;

		return currentStyle;
	},

	/**
	 * @access	public
	 */
	max: function()
	{
		
		$('lbContainer' + this.box.id).show();
		var lb = $('lightbox' + this.box.id);

		var currentStyle = this.setRestoreData(lb);;

		if (!this.restoreData[this.box.id])
		{
			this.restoreData[this.box.id] = currentStyle;
		}

		if (Object.toJSON(currentStyle)!=Object.toJSON(this.maxStyle))
		{
			lb.setStyle(this.maxStyle);
			this.getScroll();
			this.setScroll(0, 0);
			
		}
		else
		{
			lb.setStyle(this.restoreData[this.box.id]);
			this.setScroll(0, this.yPos);
		}

		lb = null;
		//resize('lbContainer' + this.box.id, 'contents' + this.box.id);
		//resizeBodyText('lbContainer' + this.box.id, 'contents' + this.box.id);
		return false;
	},

	/**
	 * @access	public
	 */
	restore: function()
	{
	},

	/**
	 * @access	public
	 */
	min: function()
	{
		$('lbContainer' + this.box.id).hide();
		var lb = $('lightbox' + this.box.id);
		this.setRestoreData(lb);

		lb.setStyle(this.minStyle);

		lb = null;
		return false;
	},

	/**
	 * 处理LightBox.
	 *
	 * @access	public
	 */
	tag: function(ctrl)
	{
		this.content = ctrl.readAttribute('href');
		ctrl.observe('click', this.doTag.bind(this), false);
		ctrl.onclick = this.empty;

		ctrl = null;
	},

	doTag : function(event)
	{
		//触发事件bug问题
		var elt = Event.element(event);

		//var elt = Event.findElement(event, 'A');  如下可兼容非A标签
		if (!elt.hasClassName('O'))
		{
			elt = elt.up('.O');
		}

		var matchPic = new RegExp("^(http|https|ftp|mms|rtsp)://[A-Za-z0-9\./=\?%_~@#:;\+\-]*[\.]+(gif|jpg|png)+$", "ig");
		if(matchPic.test(elt.readAttribute('href')))
		{
			this.processInfo(elt.readAttribute('href'), 'i');
		}
		else
		{
			this.loadInfo(elt.readAttribute('href'), {option:{formName: elt.readAttribute('form'), lbType:'n'}});
		}

		//Event.stop(event);
	},

	tooltip: function(response, type)
	{
	},
	
	/**
	 * 处理Tooltip.
	 *
	 * @access	public
	 */
	tagT: function(ctrl)
	{
		this.content = ctrl.readAttribute('href');
		ctrl.observe('click', this.doTagT.bind(this), false);
		//Event.observe(ctrl, 'mouseout', this.hideTagT.bindAsEventListener(this), false);
		ctrl.onmouseover = this.empty;
		ctrl.onclick = this.empty;
		ctrl = null;
	},

	hideTagT : function(event)
	{
		//触发事件bug问题
		var elt = Event.element(event);
		
		if ('lb_close' != elt.className)
		{
			elt = elt.up('.lb_close');
		}
		var id = elt.id.substr(2);

		this.box.zIndex -= 2  ;
		$('tooltip' + id).hide();
	},

	/**
	 * @access	public
	 */
	setRestoreTData: function(t)
	{
		var currentStyle = {};
		['top', 'left', 'width', 'height', 'borderLeftWidth', 'borderRightWidth', 'borderTopWidth', 'borderBottomWidth'].each(function(s) {currentStyle[s] = t.getStyle(s)});

		if (!this.restoreTData[t.id])
		{
			this.restoreTData[t.id] = currentStyle;
		}

		return currentStyle;
	},

	/**
	 * @access	public
	 */
	maxT: function(e)
	{
		//触发事件bug问题
		var elt = Event.element(e);
		var id =  null;

		if ('title' == elt.className)
		{
			id = elt.id.substr(6);
		}
		else if ('lb_max' != elt.className)
		{
			elt = elt.up('.lb_max');
			id = elt.id.substr(4);
		}

		//$('tooltip_cts' + id).show();
		var t = $('tooltip' + id);

		var currentStyle = this.setRestoreTData(t);

		if (!this.restoreTData[t.id])
		{
			this.restoreTData[t.id] = currentStyle;
		}

		if (Object.toJSON(currentStyle)!=Object.toJSON(this.maxStyle))
		{
			t.setStyle(this.maxStyle);
			this.getScroll();
			this.setScroll(0, 0);
		}
		else
		{
			t.setStyle(this.restoreTData[t.id]);
			
			this.setScroll(0, this.yPos);
		}

		t = null;
		elt = null;

		return false;
	},


	/**
	 * @access	public
	 */
	minT: function(e)
	{
		//触发事件bug问题
		var elt = Event.element(e);
		
		if ('lb_min' != elt.className)
		{
			elt = elt.up('.lb_min');
		}

		var id = elt.id.substr(4);
		var t = $('tooltip' + id);

		this.setRestoreTData(t);
		//$('tooltip_cts' + id).hide();

		this.setRestoreData(t);

		t.setStyle(this.minStyle);

		elt = null;
		return false;

	},

	doTagT : function(event)
	{
		event.stop();

		var defaults = {t:"", c:""};
		var options = {};
		var elt = Event.element(event);


		if (!arguments[1])
		{
			if (!elt.hasClassName('T'))
			{
				elt = elt.up('.T');
			}

			options.t = elt.innerHTML.escapeHTML();

			if (elt.readAttribute('msg'))
			{
				options.c = elt.readAttribute('msg');
			}
			else
			{
				options.c = elt.readAttribute('title');
			}
			
		}
		else
		{
			options = Object.extend(defaults, arguments[1] || {});

			if (!options.c)
			{
				alert('wrong');
				return ;
			}
		}


		options.x = Event.pointerX(event);
		options.y = Event.pointerY(event);

		this.addWindow(event, options);

		var tpl = new Template(this.getTipBox(true, this.box.tId));
		var msg_box = '';
		var msg = '';

		if (options.c)
		{
			msg = {msg:options.c};
			msg_box = tpl.evaluate(msg);
			this.processInfo(msg_box, 't', null, this.box.tId);
		}
		else
		{
			//var matchUrl = new RegExp("^(http|https)://[A-Za-z0-9\./=\?%_~@#:;\+\-]*[\.]+(php|html|htm|jsp|py|pl)+$", "ig");

			if(!elt.readAttribute('href').include('#') && !elt.readAttribute('href').include('javascript'))
			{
				msg = {msg:'<img src="' + IMA_PATH + '/js/loading2.gif"/></div>'};
				msg_box = tpl.evaluate(msg);

				this.processInfo(msg_box, 't', null, this.box.tId);
				this.loadInfo(elt.readAttribute('href'), {option:{formName: elt.readAttribute('form'), lbType:'t', tId:this.box.tId}});
			}
			else
			{
				msg = elt.readAttribute('tip');

				if (!msg)
				{
					msg = elt.readAttribute('msg');
				}

				msg = {msg:msg};
				msg_box = tpl.evaluate(msg);

				this.processInfo(msg_box, 't', null, this.box.tId);
			}

		}

		elt = null;
		msg = null;
	},

	showTipBox : function(elt, msg, close)
	{
		elt = $(elt);

		if (!elt)
		{
			return false;
		}

		var defaults = {t:"", c:""};
		var options = {};

		if (Object.isUndefined(msg))
		{
			if (elt.readAttribute('msg'))
			{
				options.c = elt.readAttribute('msg');
			}
			else
			{
				options.c = elt.readAttribute('title');
			}
		}
		else
		{
			options.c = msg;
		}

		options.x = elt.cumulativeOffset().left - 0;
		options.y = elt.cumulativeOffset().top  + 20;

		this.addWindow(elt, options);

		var tpl = new Template(this.getTipBox2(close, this.box.tId));
		var msg_box = '';
		var msg = '';

		if (options.c)
		{
			msg = {msg:options.c};
			msg_box = tpl.evaluate(msg);
			this.processInfo(msg_box, 't', null, this.box.tId);
		}
		else
		{
			//var matchUrl = new RegExp("^(http|https)://[A-Za-z0-9\./=\?%_~@#:;\+\-]*[\.]+(php|html|htm|jsp|py|pl)+$", "ig");

			if(!elt.readAttribute('href').include('#') && !elt.readAttribute('href').include('javascript'))
			{
				msg = {msg:'<img src="' + IMA_PATH + '/js/loading2.gif"/></div>'};
				msg_box = tpl.evaluate(msg);

				this.processInfo(msg_box, 't', null, this.box.tId);
				this.loadInfo(elt.readAttribute('href'), {option:{formName: elt.readAttribute('form'), lbType:'t', tId:this.box.tId}});
			}
			else
			{
				msg = elt.readAttribute('tip');

				if (!msg)
				{
					msg = elt.readAttribute('msg');
				}

				msg = {msg:msg};
				msg_box = tpl.evaluate(msg);

				this.processInfo(msg_box, 't', null, this.box.tId);
			}

		}

		elt = null;
		msg = null;
	}
});

//document.observe('dom:loaded', function ()
//{
	//window.mask = new LightBox();
//}, false);

